import { createStore } from 'vuex'
import {getMusicLyric} from '@/request/api.js'

export default createStore({
  state: {
    playList:[{
      // 给播放列表添加默认值
      al: {
        id: 89039055,
        name: "雨爱抖音版",
        pic: 109951164966568500,
        picUrl: "https://p1.music.126.net/2f6UgY8Jc0Dy6jufMdIZeQ==/109951164966568495.jpg",
        pic_str: "109951164966568495"
      },
      id: 1446137141,
      name: "雨爱（抖音版）",
      ar:[{name: "灏灏灏仔"}]
    }],
    playListIndex:0,
    isbtnShow: true, //播放按钮的显示
    playId:1446137141,
    DetailShow:false,//歌曲详情页展示
    lyricList:{},//歌词
    currentTime:0,//接收当前时间
    isLyricShow:false,//歌词显示
    duration:0,//歌曲总时长
  },
  getters: {
  },
  mutations: {
    //更改按钮的显示 true->播放 false->暂停
    updateIsbtnShow: function (state, value) {
      state.isbtnShow = value
    },
    updateplayList:function(state,value){
      state.playList = value
    },
    updateplayListIndex:function (state,value) {
      state.playListIndex = value
    },
    updateplayId:function (state,value) {
      state.playId = value
    },
    updateDetailShow:function(state){
      state.DetailShow=!state.DetailShow,
      state.isLyricShow=false
    },
    updateLyricList:function(state,value){
      state.lyricList=value
    },
    updateCurrentTime:function(state,value){
      // console.log(state.currentTime);
      state.currentTime=value
    },
    updateIsLysrcShow:function(state,value){
      state.isLyricShow=value
    },
    updateDuration:function(state,value){
      state.duration=value
    }
  },
  actions: {
    getLyric: async function (context,value) {
      let res = await getMusicLyric(value)
      console.log('获取歌词');
      console.log(res);
      context.commit("updateLyricList",res.data.lrc);
    },
    updateDuration:function(state,value){
      state.duration=value
    },
  },
  modules: {
  }
})
